package com.atguigu.sparkcore.day04

import org.apache.spark.broadcast.Broadcast
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * Author atguigu
 * Date 2020/10/31 10:59
 */
object BdDemo {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("BdDemo").setMaster("local[2]")
        val sc: SparkContext = new SparkContext(conf)
        val list1 = List(30, 50, 70, 60, 10, 20)
        val rdd1: RDD[Int] = sc.parallelize(list1, 2)
        val a = new Array[Int](1000000)
    
        val bd: Broadcast[Array[Int]] = sc.broadcast(a)
        rdd1.foreach(x => {
            val arr: Array[Int] = bd.value
            println(arr.mkString(","))
        })
        
        sc.stop()
        
    }
}
/*
累加器:
 共享变量写的问题
 
共享读的问题:
    广播变量
    
    广播到每个executor上, 而不用每个task一个
    大变量的读的问题
 


 */